#coding:utf8
import cherrypy
import datetime
from ConnectMSSQL import ms

from head import print_head
from end import print_end

from utf8code import *

_top = """
        <form>
        <div id="div_operate">
            <table width="auto">
              <tr>
                <td class="class_td">设备编号:</td>
                <td><font>%s</font></td>
                <td class="class_td">固定资产编号:</td>
                <td><font>%s</font></td>
                <td class="class_td">购买日期:</td>
                <td>%s</td>
              </tr>
              <tr>
                <td class="class_td">设备类型:</td>
                <td>%s</td>
                <td class="class_td">品牌及型号:</td>
                <td>%s</td>
                <td class="class_td">设备名称:</td>
                <td>%s</td>
              </tr>
              <tr>
                <td class="class_td">基本配置:</td>
                <td colspan="5">%s</td>
              </tr>
              <tr>
                <td class="class_td">网络配置:</td>
                <td colspan="5">%s</td>
              </tr>
              <tr>
                <td class="class_td">随机附件:</td>
                <td colspan="5">%s</td>
              </tr>
              <tr>
                <td class="class_td" colspan="6">设备备注：</td>
              </tr>
              <tr>
                <td height="120" colspan="6">%s</td>
              </tr>
            </table>
        </div>
        <div>
            <table width="auto">
              <tr>
                <th class="class_th" scope="col">#</th>
                <th class="class_th" scope="col">部门</th>
                <th class="class_th" scope="col">使用人</th>
                <th class="class_th" scope="col">变更日期</th>
                <th class="class_th" scope="col">经手人</th>
                <th class="class_th" scope="col">备注</th>
              </tr>
        """
           
_end = """
            </table>
        </div>
    </form>
"""



class SBDAK:
    @cherrypy.expose
    def index(self,sbbh):
        sql_sbxx = """
            SELECT SBBH
                ,GDZCBH
                ,GMRQ
                ,SBLX
                ,PPXH
                ,SBMC
                ,JBPZ
                ,WLPZ
                ,SJFJ
                ,BZ
            FROM T_SB
            WHERE SBBH = '%s'
        """
        
        dataList_1 = ms.ExecQuery(sql_sbxx % sbbh)
        _mid_1 = ''
        for sbxx in dataList_1:
            _mid_1 = _top % (sbxx[0],sbxx[1],datetime.datetime.strftime(sbxx[2],'%Y-%m-%d'),sbxx[3],sbxx[4],sbxx[5],sbxx[6],sbxx[7],sbxx[8],sbxx[9])

        
        _mid_tmp = """            
                    <tr>
                        <td width="5%%">%s</td>
                        <td width="15%%"></td>
                        <td width="15%%"></td>
                        <td width="15%%"></td>
                        <td width="15%%"></td>
                        <td width="35%%"></td>
                    </tr>
                    """
        _mid_2 = ''
        for i in range(23)[1:]:
            _mid_2 += _mid_tmp % i

        return utf8code(print_head % ('设备管理卡打印','计算机设备档案卡')  + _mid_1 + _mid_2 + _end + print_end)